const http = require('http');
const url = require('url');
const router = require('./router');// 业务分离后的route

const app = http.createServer((req, res) => {
  let path = null;

  if (req.method === 'GET') {
    let { pathname, query } = url.parse(req.url, true);
    path = pathname;
    handleGetMethod();

    function handleGetMethod() {
      // 在这里我们只实现来一个接口
      // 获取新闻列表
      if (path === '/getAllNews') {
        router.newsList(req, res);
      } else {
        //如果匹配不到，说明该接口尚未开发完成，页面显示，该接口正在开发中
        router.noResult(req, res);
      }
    }
  }
});

app.listen(8008, () => {
  console.log('port 8008 is running...');
})